﻿using System;
using System.Web.UI;
using Project.Model;
using Project.Common;
using System.Web.UI.WebControls;

namespace Web
{
    /// <summary>
    /// 功能：编辑页面
    ///       (Basictable)
    /// 作者：Author
    /// 日期：2011-2-14
    /// </summary>
    public partial class IndexBasictable_Edit : AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //此处添加需要绑定的控件
                base.BindEnum2WebControls(Chsh_managementDropDownList, typeof(EnumChsh_management), false, 0);

                if (this.SID > 0)
                {
                    // 编辑状态
                    Indexbasictable model = ManagerFactory.IndexbasictableManager.Get(this.SID);
                    if (model == null)
                    {
                        Alert("记录不存在!");
                        ExecJsAjax("window.close();", Page);
                        return;
                    }

                    // 绑定页面控件与对象的值
                    base.BindControlsValue(Master.FindControl("ContentPlaceHolder1").Controls, model, true);

                    // 以下添加页面控件自定义显示代码

                }
                else
                {
                    // 新建
                }

                // 查看
                if (Request.Params["isenable"] != null)
                {
                    ClientScript.RegisterStartupScript(typeof(Page), "a", "<script>ChangeToLabel();</script>");
                }

            }

        }

        protected void saveButton_Click(object sender, System.EventArgs e)
        {
            if (IsValid)
            {
                Indexbasictable model = new Indexbasictable();

                try
                {
                    if (this.SID > 0)
                    {
                        // 更新
                        model = ManagerFactory.IndexbasictableManager.Get(this.SID);
                    }
                    else
                    {
                        // 新建
                    }

                    if (model == null)
                    {
                        Alert("记录不存在!");
                        ExecJsAjax("window.close();", Page);
                        return;
                    }

                    // 绑定页面控件与对象的值
                    model = base.BindControlsValue(Master.FindControl("ContentPlaceHolder1").Controls, model, false);

                    if (this.SID > 0)
                    {
                        // 更新
                        ManagerFactory.IndexbasictableManager.Update(model);
                    }
                    else
                    {
                        // 新建
                        ManagerFactory.IndexbasictableManager.Save(model);
                    }
                    Alert("保存成功!");
                    ExecJsAjax("window.opener.searchRefresh();window.close();", Page);
                }
                catch (Exception ex)
                {
                    Alert(ex.Message);
                }
            }
        }

        #region 前端验证
        ///// <summary>
        ///// 验证 Id(数据类型: long)
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="args"></param>
        //protected void CheckId(object source, ServerValidateEventArgs args)
        //{
        //    // 字段不能为空
        //    args.IsValid = Validator.IsInt(txt_Id.Text);
        //}

        /// <summary>
        /// 验证 Jh_name(数据类型: string) 长度 
        /// </summary>
        /// <param name="source"></param>
        /// <param name="args"></param>
        //protected void CheckJh_name(object source, ServerValidateEventArgs args)
        //{
        //    // 字段可以为空
        //    if (!string.IsNullOrEmpty(txt_Jh_name.Text))
        //    {
        //        args.IsValid = txt_Jh_name.Text.Length <= 200;
        //    }
        //}

        ///// <summary>
        ///// 验证 Chsh_management(数据类型: string) 长度 
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="args"></param>
        //protected void CheckChsh_management(object source, ServerValidateEventArgs args)
        //{
        //    // 字段可以为空
        //    if (!string.IsNullOrEmpty(txt_Chsh_management.Text))
        //    {
        //        args.IsValid = txt_Chsh_management.Text.Length <= 200;
        //    }
        //}

        /// <summary>
        /// 验证 Item_name(数据类型: string) 长度 
        /// </summary>
        /// <param name="source"></param>
        /// <param name="args"></param>
        protected void CheckItem_name(object source, ServerValidateEventArgs args)
        {
            // 字段可以为空
            if (!string.IsNullOrEmpty(txt_Item_name.Text))
            {
                args.IsValid = txt_Item_name.Text.Length <= 200;
            }
        }

        /// <summary>
        /// 验证 Item_people(数据类型: string) 长度 
        /// </summary>
        /// <param name="source"></param>
        /// <param name="args"></param>
        protected void CheckItem_people(object source, ServerValidateEventArgs args)
        {
            // 字段可以为空
            if (!string.IsNullOrEmpty(txt_Item_people.Text))
            {
                args.IsValid = txt_Item_people.Text.Length <= 50;
            }
        }

        /// <summary>
        /// 验证 Item_people_tel(数据类型: string) 长度 
        /// </summary>
        /// <param name="source"></param>
        /// <param name="args"></param>
        protected void CheckItem_people_tel(object source, ServerValidateEventArgs args)
        {
            // 字段可以为空
            if (!string.IsNullOrEmpty(txt_Item_people_tel.Text))
            {
                args.IsValid = txt_Item_people_tel.Text.Length <= 50;
            }
        }

        /// <summary>
        /// 验证 Tjdw_sort(数据类型: string) 长度 
        /// </summary>
        /// <param name="source"></param>
        /// <param name="args"></param>
        protected void CheckTjdw_sort(object source, ServerValidateEventArgs args)
        {
            // 字段可以为空
            if (!string.IsNullOrEmpty(txt_Tjdw_sort.Text))
            {
                args.IsValid = txt_Tjdw_sort.Text.Length <= 200;
            }
        }

        /// <summary>
        /// 验证 Tjdw_name(数据类型: string) 长度 
        /// </summary>
        /// <param name="source"></param>
        /// <param name="args"></param>
        protected void CheckTjdw_name(object source, ServerValidateEventArgs args)
        {
            // 字段可以为空
            if (!string.IsNullOrEmpty(txt_Tjdw_name.Text))
            {
                args.IsValid = txt_Tjdw_name.Text.Length <= 200;
            }
        }


        /// <summary>
        /// 验证 Shbdw_name(数据类型: string) 长度 
        /// </summary>
        /// <param name="source"></param>
        /// <param name="args"></param>
        protected void CheckShbdw_name(object source, ServerValidateEventArgs args)
        {
            // 字段可以为空
            if (!string.IsNullOrEmpty(txt_Shbdw_name.Text))
            {
                args.IsValid = txt_Shbdw_name.Text.Length <= 200;
            }
        }

        /// <summary>
        /// 验证 USERNAME(数据类型: string) 长度 
        /// </summary>
        /// <param name="source"></param>
        /// <param name="args"></param>
        protected void CheckUSERNAME(object source, ServerValidateEventArgs args)
        {
            // 字段可以为空
            if (!string.IsNullOrEmpty(txt_USERNAME.Text))
            {
                args.IsValid = txt_USERNAME.Text.Length <= 50;
            }
        }

        /// <summary>
        /// 验证 Jh_year(数据类型: string) 长度 
        /// </summary>
        /// <param name="source"></param>
        /// <param name="args"></param>
        protected void CheckJh_year(object source, ServerValidateEventArgs args)
        {
            // 字段可以为空
            if (!string.IsNullOrEmpty(txt_Jh_year.Text))
            {
                args.IsValid = txt_Jh_year.Text.Length <= 10;
            }
        }



        #endregion

    }
}